package classes
{
	import classes.event.QueryEvent;
	import classes.tfo.PostBattleResponseTO;
	import classes.tfo.PostNPCConversationLogicTO;
	import classes.tfo.PostResponseTO;
	import classes.tfo.WrappedCharacterInfoTO;
	
	import flash.net.NetConnection;
	import flash.net.Responder;
	
	import mx.collections.ArrayCollection;

	public class GeneralServiceInteracter extends BasedServiceInteracter
	{
		private var getWrappedCharacterInfoResponder:Responder;
		private var postNewPositionResponder:Responder;
		private var postBattleResponseResponder:Responder;
		private var dev_getSkillListResponder:Responder;
		private var postActionToNPCResponder:Responder;
		
		public function GeneralServiceInteracter(_nc:NetConnection) {
			super(_nc);
			getWrappedCharacterInfoResponder = new Responder(handleGetWrappedCharacterInfoResponder, statusResult);
			postNewPositionResponder = new Responder(handlePostNewPositionResponder, statusResult);
			postBattleResponseResponder = new Responder(handlePostBattleResponseResponder, statusResult);
			dev_getSkillListResponder = new Responder(handleDev_getSkillResponder, statusResult);
			postActionToNPCResponder = new Responder(handleActionToNPCResponder, statusResult);
		}
		
		public function getWrappedCharacterInfo():void {
			getNetConnector().call("general.getWrappedCharacterInfo", getWrappedCharacterInfoResponder);
		}
		
		public function postNewPosition(corx:int, cory:int):void {
			getNetConnector().call("general.postNewPosition", postNewPositionResponder, (corx * 1000) + cory);
		}
		
		public function postBattleResponse(monsterId:int, actionId:int):void {
			getNetConnector().call("general.postBattleResponse", postBattleResponseResponder, monsterId, actionId);
		}
		
		public function dev_getSkillList():void {
			if(StrategyManager.getInstance().hasDev_Skill) {
				dispatchEvent(new QueryEvent(QueryEvent.LOAD_DEV_SKILL, StrategyManager.getInstance().dev_skillProvider.source));
			} else {
				getNetConnector().call("general.dev_getSkillList", dev_getSkillListResponder);
			}
		}
		
		public function postActionToNPC(npcId:int, actionId:int):void {
			getNetConnector().call("general.postActionToNPC", postActionToNPCResponder, npcId, actionId);
		}
		
		
		private function handleActionToNPCResponder(val:PostNPCConversationLogicTO):void {
			dispatchEvent(new QueryEvent(QueryEvent.NPC_ACTION, val));
		}
		
		private function handleDev_getSkillResponder(val:Array):void {
			StrategyManager.getInstance().dev_skillProvider = new ArrayCollection(val);
			dispatchEvent(new QueryEvent(QueryEvent.LOAD_DEV_SKILL, val));
		}
		
		private function handleGetWrappedCharacterInfoResponder(item:WrappedCharacterInfoTO):void {
			dispatchEvent(new QueryEvent(QueryEvent.LOAD_CHARACTER, item));
		}
		
		private function handlePostNewPositionResponder(item:PostResponseTO):void {
			dispatchEvent(new QueryEvent(QueryEvent.MOVE, item));
		}
		
		private function handlePostBattleResponseResponder(item:PostBattleResponseTO):void {
			dispatchEvent(new QueryEvent(QueryEvent.BATTLE_COMPLETE, item));
		}
		
		
		
		
	}
}